package com.example.coco.Controller;


import com.example.coco.res.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.awt.*;
import java.util.Map;

@RestController
public class AdminLog {
    @Autowired
    AdminMapper adminMapper;

    @RequestMapping("/adlogin")
    public Object adLog(@RequestParam Map<String, Object> params) {
        String id = (String) params.get("userid");
        String password = adminMapper.adminlog(id);
        String newpassword = (String) params.get("userpassword");

        if (id == null || id.isEmpty() || password == null || password.isEmpty() || newpassword == null || newpassword.isEmpty() || !password.equals(newpassword)) {
            System.out.println("请重新输入管理员的用户名和密码");
            return new ModelAndView("loginError");
        } else if (password.equals(newpassword)) {
            System.out.println("登录成功");
            return new ModelAndView("Adminindex");
        }

        System.out.println("404");
        return "连接超时";
    }
}
